define(["jquery", "bootstrap", "userend", "table", "form"], function ($, undefined, Userend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-add").data("area", ["1000px","800px"]);
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: "mall/shop/freight/index",
                    add_url: "mall/shop/freight/add",
                    edit_url: "mall/shop/freight/edit",
                    del_url: "mall/shop/freight/del",
                    multi_url: "mall/shop/freight/multi",
                    table: "mall_shop_freight"
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: "id",
                sortName: "weigh",
                columns: [
                    [
                        {checkbox: true},
                        {field: "id", title: __("Id")},
                        {field: "name", title: __("Name")},
                        {field: "method", title: __("Method"), searchList: {"2":__("Method 2"),"3":__("Method 3")}, formatter: Table.api.formatter.normal},
                        {field: "weigh", title: __("Weigh")},
                        {field: "createtime", title: __("Create time"), operate:"RANGE", addclass:"datetimerange", formatter: Table.api.formatter.datetime},
                        {field: "updatetime", title: __("Update time"), operate:"RANGE", addclass:"datetimerange", formatter: Table.api.formatter.datetime},
                        {field: 'datalist', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'freightprice',
                                    text: "快递报价",
                                    classname: 'btn btn-xs btn-info btn-fields btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'mall/shop/freightprice?freight_id={ids}'
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },

                        {field: "operate", title: __("Operate"), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});